package com.sky.mapper;


import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingMapper {


    /**
     * 动态获取购物车数据
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> listShopping(ShoppingCart shoppingCart);


    /**
     * 根据ID修改商品数量
     * @param cart
     */
    @Update("update sky_take_out.shopping_cart set number = #{number} where id = #{userId}")
    void updateNumberById(ShoppingCart cart);


    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into sky_take_out.shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insertShopping(ShoppingCart shoppingCart);


    /**
     * 查看购物车
     * @param currentId
     * @return
     */
    @Select("select  * from sky_take_out.shopping_cart where user_id = #{currentId}")
    List<ShoppingCart> selectShoppingByUserId(Long currentId);


    /**
     * 清空购物车
     * @param currentId
     */
    @Delete("delete from sky_take_out.shopping_cart where user_id = #{currentId}")
    void deleteShoppingByUserId(Long currentId);
}
